<?php
include_once('admin.inc.php');
$do = get_param("do");
switch($do){
	case 'index':
	default:
		$smarty->display('admin/index.html');
	break;
	case 'nav':
		$navModel = new Model('nav');
		$list = $navModel->order('sort')->get();
		$smarty->assign('list', $list);
		// 分类
		$catModel = new Model('category');
		$cats = $catModel->order('pid, id')->get();
		$smarty->assign('cats', $cats);
		$smarty->display('admin/navmgr.html');
	break;
	case 'addNav':
		$data = get_data();
		if( empty($data['title']) ){
			msg('导航名称不能为空');
			exit;
		}
		unset($data['id']);
		$navModel = new Model('nav');
		$rs = $navModel->value($data)->add();
		if( $rs && $rs>0 ){
			msg('添加成功','index.php?do=nav');
		}else{
			msg('添加失败');
		}
		exit;
	break;
	case 'editNav':
		$data = get_data();
		if( empty($data['title']) ){
			msg('导航名称不能为空','index.php?do=nav');
			exit; 
		}
		$id = intval($data['id']);
		unset($data['id']);
		if( empty($id) ){
			msg('非法提交',-1);
			exit;
		}
		$navModel = new Model('nav');
		$rs = $navModel->where("id=$id")->value($data)->update();
		if( $rs ){
			msg('修改成功', 'index.php?do=nav');
		}else{
			msg('修改失败', -1);
		}
	break;
	case 'delNav':
		$id = intval(get_param('id'));
		if( empty($id) ){
			msg('非法id',-1);
		}
		$navModel = new Model('nav');
		$rs = $navModel->where("id=$id")->del();
		if( $rs ){
			ajax_return(array('status'=>'success','info'=>'删除成功'));
		}else{
			ajax_return(array('status'=>'failed','info'=>'删除失败'));
		}
		
	break;
}
